package com.netrust.cmsx.admin.modules.sys.web;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.ConstraintViolationException;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.netrust.cmsx.admin.modules.sys.service.UserService;
import com.netrust.cmsx.core.config.Global;
import com.netrust.cmsx.core.page.PageKey;
import com.netrust.cmsx.core.page.jq.JqGrid;
import com.netrust.cmsx.core.page.jq.JqPost;
import com.netrust.cmsx.core.page.jq.convert.Page2JQ;
import com.netrust.cmsx.core.validator.BeanValidators;
import com.netrust.cmsx.core.web.BaseController;
import com.netrust.cmsx.entity.module.sys.User;
import com.netrust.cmsx.utils.data.DateUtils;
import com.netrust.cmsx.utils.string.StringUtils;


/**
 * 用户Controller
 */
@Controller
@RequestMapping(value = "xs")
public class DemoController extends BaseController {
	@Autowired
	UserService userService;

	@RequestMapping(value = {""})
	public String get(PageKey pk, Model model) {
		
//		Page<User> page =userService.findList(pk);
		
//		JqGrid jg=new Page2JQ<User>().run(page, new String[]{"loginName","name"});
//		
//		model.addAttribute("page", page);
		return "modules/sys/sysIndex";
	}
	
	@ResponseBody
	@RequestMapping(value = {"jq"})
	public JqGrid jq(JqPost jqPost) {
		PageKey pk=new PageKey(null, jqPost.getPage(),jqPost.getRows());
		
		Page<User> page =userService.findList(pk);
		
		JqGrid jg=new Page2JQ<User>().run(page, new String[]{"loginName","name"});
		
		//System.out.println(jg.getPage()+"-----------");
		//System.out.println(pk.getPageNum()+"----getPageNum-------");
		//jg.setPage(pk.getPageNum().toString());
		//System.out.println(jg.getPage()+"----jg.getPage()-------");
		
		System.out.println(JSONObject.toJSONString(jg));
		
		return jg;
	}

}
